package testing;


import junit.framework.Assert;
import logicaDePredicados.LogicOperatorFactory;
import logicaDePredicados.LogicPredicate;
import logicaDePredicados.Pair;
import logicaDePredicados.PredicateConstant;
import logicaDePredicados.PredicateVariable;
import logicaDePredicados.QuantifierStrategy;
import logicaDePredicados.SimpleStrategy;
import logicaDePredicados.SkolemFunction;

import org.junit.Before;
import org.junit.Test;
import exceptions.UnBalancedExpressionException;
import exceptions.UnDecidibleValueException;
import logicaDePredicados.Sentence;



public class SentenceTest {
	private LogicPredicate<String> animal;
	private LogicPredicate<String> mammal;
	private PredicateConstant<String> perro;
	private PredicateConstant<String> helecho;
	private Sentence sentencia = new Sentence (new SimpleStrategy());
	private LogicPredicate<String> dog;
	private PredicateVariable <String> x = new PredicateVariable<String >("X","X");
	private LogicPredicate<String> bird; 
	private LogicPredicate<Pair<String,String>> loves= new LogicPredicate<Pair<String,String>>("LOVES");
	private LogicPredicate<Pair<String,String>> hates= new LogicPredicate<Pair<String,String>>("HATES");
	private SkolemFunction<String, String> siblingOf = new SkolemFunction<String, String>("sibling-Of");
	private LogicPredicate<String>hasSibling = new LogicPredicate<String>("HASSIBILING");
	/**
	 * @throws Exception
	 */
	/**
	 * @throws Exception
	 */
	@Before
	public void setUp() throws Exception {
		animal = new LogicPredicate<String>("ANIMAL");
		mammal = new LogicPredicate<String>("MAMMAL");
		dog = new LogicPredicate<String>("DOG");
		bird =  new LogicPredicate<String>("BIRD");
		perro = new PredicateConstant<String>("perro","PERRO");
		helecho= new PredicateConstant<String>("helecho","HELECHO");
		animal.addTruthValue("perro",new Boolean (true));
		animal.addTruthValue("ganso",new Boolean (true));
		animal.addTruthValue("pato",new Boolean (true));
		animal.addTruthValue("zorro",new Boolean (true));
		animal.addTruthValue("gallo",new Boolean (true));
		animal.addTruthValue("gallina",new Boolean (true));
		animal.addTruthValue("pez",new Boolean (true));
		animal.addTruthValue("ballena",new Boolean (true));
		animal.addTruthValue("mesa",new Boolean (false));
		animal.addTruthValue("silla",new Boolean (false));
		animal.addTruthValue("balcon",new Boolean (false));
		animal.addTruthValue("termo",new Boolean (false));
		animal.addTruthValue("pitbull",new Boolean (true));
		animal.addTruthValue("chihuahua",new Boolean (true));
		animal.addTruthValue("terrier",new Boolean (true));
		animal.addTruthValue("sheppard",new Boolean (true));
		dog.addTruthValue("pitbull",new Boolean (true));
		dog.addTruthValue("chihuahua",new Boolean (true));
		dog.addTruthValue("terrier",new Boolean (true));
		dog.addTruthValue("sheppard",new Boolean (true));
		bird.addTruthValue("canario", true);
		bird.addTruthValue("colibrí", true);
		bird.addTruthValue("paloma", true);
		bird.addTruthValue("perro", false);
		bird.addTruthValue("chihuahua", false);
		bird.addTruthValue("gato", false);
		loves.addTruthValue(new Pair<String, String>("John","Mary"), true);
		loves.addTruthValue(new Pair<String, String>("John","John"), true);
		loves.addTruthValue(new Pair<String, String>("John","Peter"), false);
		loves.addTruthValue(new Pair<String, String>("John","Julie"), true);
		loves.addTruthValue(new Pair<String, String>("Julie","Mary"), true);
		loves.addTruthValue(new Pair<String, String>("John","Mark"), true);
		loves.addTruthValue(new Pair<String, String>("John","Ursula"), false);
		loves.addTruthValue(new Pair<String, String>("Ursula","Mary"), false);
		loves.addTruthValue(new Pair<String, String>("Ursula","John"), false);
		loves.addTruthValue(new Pair<String, String>("Ursula","Mark"), false);
		loves.addTruthValue(new Pair<String, String>("Mary","John"), false);
		hates.addTruthValue(new Pair<String, String>("John","Mary"), false);
		hates.addTruthValue(new Pair<String, String>("John","Peter"), true);
		siblingOf.addValue("John", "Ursula");
		siblingOf.addValue("Ursula","John");
		hasSibling.addTruthValue("John", true);
	}
	/**
	 * @throws UnDecidibleValueException 
	 * 
	 */
	/**
	 * @throws UnDecidibleValueException
	 * @throws UnBalancedExpressionException 
	 */
	@Test
	public void testCase () throws UnDecidibleValueException, UnBalancedExpressionException{

		PredicateConstant<Pair<String,String>> juanMaria = new PredicateConstant<Pair<String,String>>(new Pair<String, String>("John","Mary"));
		PredicateConstant<Pair<String, String>> juanPedro = new PredicateConstant<Pair<String,String>>(new Pair<String, String>("John","Peter"));
		PredicateConstant<Pair<String, String>> juanUrsula = new PredicateConstant<Pair<String,String>>(new Pair<String, String>("John","Ursula"));
		PredicateConstant<String> john = new PredicateConstant<String>("John");
		PredicateConstant<String> ursula = new PredicateConstant<String>("Ursula");
//		sentencia.add(hasSibling);
//		sentencia.add(siblingOf);
//		sentencia.add(ursula);
//		sentencia.add(LogicOperatorFactory.createTHEN());
//		sentencia.add(LogicOperatorFactory.createNOT());
//		sentencia.add(LogicOperatorFactory.createLeftBracket());
//		sentencia.add(loves);
//		sentencia.add(juanUrsula);
//		sentencia.add(LogicOperatorFactory.createRightBraket());
//		
		
		sentencia.add(loves);
		sentencia.add(juanMaria);
		sentencia.add(LogicOperatorFactory.createAND());
		sentencia.add(hates);
		sentencia.add(juanPedro);
		
		System.out.println("sentencia");
		System.out.println(sentencia.rawFormat());
		Sentence clon = sentencia.clone();
		System.out.println("clon");
		System.out.println(clon.rawFormat());
		Assert.assertEquals(sentencia, clon);
		
		Assert.assertEquals(true, sentencia.parse());
	}

}
